#!/usr/bin/env python
"""
启动Streamlit实验结果查看器
"""
import sys
import os
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

# 设置环境变量（如果需要）
os.environ.setdefault("DATABASE_URL", "sqlite:///./param_management.db")

if __name__ == "__main__":
    import subprocess
    
    # Streamlit应用的路径
    viewer_path = project_root / "param_management_client" / "backend" / "view_experiments.py"
    
    print(f"启动Streamlit查看器: {viewer_path}")
    print(f"数据库路径: {os.environ.get('DATABASE_URL', 'sqlite:///./param_management.db')}")
    print("\n浏览器将自动打开，如果没有自动打开，请访问: http://localhost:8501\n")
    
    # 运行Streamlit
    subprocess.run([
        sys.executable, "-m", "streamlit", "run", 
        str(viewer_path),
        "--server.port=8501",
        "--server.address=localhost"
    ])

